package cl.blueprintsit.utils.files;

import jcifs.smb.SmbFile;
import org.junit.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

import static cl.blueprintsit.utils.files.FileUtils.*;
import static junit.framework.Assert.*;

public class FileUtilsTest {

    @Test
    public void testConnect() throws Exception {
        assertTrue(connect("c:/temp"));
    }

    @Test
    public void testConnectSharedWindowsFolder() throws Exception {
        assertTrue(connect("\\\\PC-ANDRES\\movies"));
    }

    @Test
    public void testConnectFail() throws Exception {
        assertFalse(connect("c:/non-existing_file"));
    }

    @Test
    public void testGetFilesFromFolder01() throws Exception {
        File sharedFolder = new File("\\\\PC-ANDRES\\movies");

        List<File> filesFromFolder = getFilesFromFolder(sharedFolder);
        assertNotNull(filesFromFolder);

        /* The files are listed */
        for (File file : filesFromFolder) {
            System.out.println(file.getName());
        }
    }

    @Test
    public void testGetFilesFromFolderSamba() throws Exception {
        List<SmbFile> filesFromFolder = getFilesFromSambaFolder("IVAN-SAMSUNG-PC", "Andres", "af1", "WindowsShared/");
        assertNotNull(filesFromFolder);

        /* The files are listed */
        for (SmbFile file : filesFromFolder) {
            System.out.println(file.getName());
        }
    }

    @Test(expected = FileNotFoundException.class)
    public void testGetFilesFromFolderFail() throws FileNotFoundException {
        File sharedFolder = new File("\\\\NoPC\\noFolder");

        if (!sharedFolder.exists())
            getFilesFromFolder(sharedFolder);
    }
}
